import VueRouter from 'vue-router'
import Vue from 'vue'
Vue.use(VueRouter)
// 防止浏览器-控制台报错（Navigating to current location ("/") is not allowed）
const VueRouterPush = VueRouter.prototype.push 
VueRouter.prototype.push = function push (to) {
    return VueRouterPush.call(this, to).catch(err => err)
}
const routes=[
    {
        name: 'index',
        path: '/',
        component: () => import('../views/home/index'),
        meta:{
            title:'上海图书馆近代图书知识库'
        }
    },{
        name: 'main',
        path: '/main',
        redirect:'/categorySearch',
        component: () => import('../components/layout/layout'),
        children:[
            {
                name: 'categorySearch',
                path: '/categorySearch',
                component: () => import('../views/categorySearch/index'),
                meta:{
                    title:'上海图书馆近代图书知识库',
                    pageName:'分类浏览'
                }
            },
            {
                name: 'advanceSearch',
                path: '/advanceSearch',
                component: () => import('../views/advanceSearch/index'),
                meta:{
                    title:'上海图书馆近代图书知识库',
                    pageName:'高级检索'
                }
            },
            {
                name: 'moreVersion',
                // path: '/moreVersion/:id',
                path: '/moreVersion',
                component: () => import('../views/moreVersion/index'),
                meta:{
                    title:'上海图书馆近代图书知识库',
                    pageName:'更多版本'
                }
            },
            {
                name: 'instanceDetail',
                // path: '/instanceDetail/:id',
                path: '/instanceDetail',
                component: () => import('../views/instanceDetail/index'),
                meta:{
                    title:'上海图书馆近代图书知识库',
                    pageName:'书目详情'
                }
            },
            {
                name: 'mapSearch',
                path: '/mapSearch',
                component: () => import('../views/mapSearch/index'),
                meta:{
                    title:'上海图书馆近代图书知识库',
                    pageName:'地图检索'
                }
            }
        ]
    }
]

const router=new VueRouter({
    mode: 'history',
    routes
})

router.beforeEach((to,from,next)=>{
    if(to.meta.title)document.title=to.meta.title
    next()
})

export default router
